<?php
/**
 * desc Created by wang.
 * User: wang
 * motto: 是时候为小时候吹过的牛而努力了!
 * Date: 2020/3/23 16:10
 */

namespace app\admin\validate;


use think\Validate;

class Manager extends Validate
{
    protected $rule = [
        'username' => 'require|unique:admin_user|length:3,16|regex:^[a-zA-Z0-9]*$',
        'password' => 'require|length:6,16|regex:^(?=.*[a-zA-Z])(?=.*?[0-9])[\s\S]*$',
        'real_name' => 'require|chsAlpha',
        'role_id' => 'require|regex:^[1-9]{1}[\d]*$',
        'status' => 'in:0,1',
    ];

    protected $message = [
        'username.require' => '账号不能为空',
        'username.unique' => '账号以存在',
        'username.length' => '账号长度为3-16',
        'username.regex' => '账号只能为数字、字母',
        'password.require' => '密码不能为空',
        'password.length' => '密码长度为6-16',
        'password.regex' => '密码必须同时包含字母和数字',
        'real_name.require' => '真实姓名不能为空',
        'real_name.chsAlpha' => '真实姓名只能为汉字、字母',
        'role_id.require' => '必须选角色',
        'role_id.regex' => '必须选角色',
        'status.in' => '必须选择状态',
    ];

    //需要校验的场景
    protected $scene = [
        'add' => ['username', 'password', 'real_name', 'role_id', 'status'],
        'edit' => ['username', 'real_name', 'role_id', 'status'],
        'status' => ['id', 'status'],
        'del' => ['id'],
    ];
}